﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AddressBook
{
    public partial class LOVE : Form
    {
        private Timer timer; // 定义定时器成员变量
        public LOVE()
        {
            InitializeComponent();
            pictureBox1.Image = Image.FromFile(@"D:\程序语言设计\AddressBook\AddressBook\Properties\FormLoginPicture.jpg");
            pictureBox2.Image = Image.FromFile(@"D:\程序语言设计\AddressBook\AddressBook\Properties\FormLogin1.gif");
            pictureBox3.Image = Image.FromFile(@"D:\程序语言设计\AddressBook\AddressBook\Properties\FormLogin2.gif");
            pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage; // 根据需要调整大小模式
            pictureBox3.SizeMode = PictureBoxSizeMode.StretchImage; // 根据需要调整大小模式

            // 初始化定时器，每天触发一次
            timer = new Timer();
            timer.Interval = (int)TimeSpan.FromDays(1).TotalMilliseconds;
            timer.Tick += Timer_Tick;
            timer.Start();

            // 立即计算并显示天数
            CalculateDaysPassed();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            // 当定时器触发时，重新计算天数
            CalculateDaysPassed();
        }

        private void CalculateDaysPassed()
        {
            // 定义固定的纪念日
            DateTime anniversary = new DateTime(2022, 10, 12);

            // 获取当前日期
            DateTime today = DateTime.Today;

            // 确保纪念日早于或等于今天
            if (anniversary > today)
            {
                MessageBox.Show("纪念日设置有误，它不能在未来！");
                return;
            }

            // 计算两个日期之间的差异
            TimeSpan difference = today - anniversary;

            // 显示天数，转换为整数天数
            int daysPassed = (int)difference.TotalDays;
            labelDaysPassed.Text = $"我们在一起 {daysPassed} 天";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            // 检查是否为水印文本
            string uid = txtUid.Text != txtUid.WatermarkText ? txtUid.Text : "";
            string pwd = txtPwd.Text != txtPwd.WatermarkText ? txtPwd.Text : "";

            if (this.txtUid.Text == "Zhangqiuyue" && this.txtPwd.Text == "Zhangqiuyue")
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("错误的用户名或密码");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
       

    private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void labelDaysPassed_Click(object sender, EventArgs e)
        {

        }

        private void MyInformation_Click(object sender, EventArgs e)
        {
            using (FormMyInformation newForm = new FormMyInformation())
            {
                newForm.ShowDialog();
            }

        }

        private void LOVE_Load(object sender, EventArgs e)
        {

        }
    }
}
